/*************************************************************************
	> File Name: P5146.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-03-19 15:52:08
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long min_m, ans = LLONG_MIN;
    cin >> min_m;
    for (int i = 1, x; i < n; i++) {
        scanf("%d", &x);
        if (x - min_m > ans) ans = x - min_m;
        if (x < min_m) min_m = x;
    }
    cout << ans << endl;
    return 0;
}
